package com.xiaoshuidi.cloud.module.rooms.mq.producer;

import com.alibaba.fastjson.JSONObject;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.roomel.vo.RoomelCreateReqVO;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.roomel.vo.RoomelUpdateReqVO;
import com.xiaoshuidi.cloud.module.rooms.service.IRoomelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 推送到MQ-房源
 * @Param
 * @Return
 * @Date 2023/5/16 17:36
 * @Author Link
 **/
@Component
@Slf4j
public class RoomEsProducer {
    @Resource
    private StreamBridge streamBridge;
    @Autowired
    private IRoomelService iRoomelService;

    //推送到MQ-房源-更新
    public void updateRoomEl(RoomelUpdateReqVO roomelUpdateReqVO) {
        log.info("消费者-RoomEsConsumerA : message = " + roomelUpdateReqVO.toString());
        Boolean result = iRoomelService.updateCover(roomelUpdateReqVO);
        log.info("消费-房源-单个更新，消费是否成功："+result);
        //streamBridge.send("RoomEsConsumerUpdate-out-0", roomelUpdateReqVO);
    }

//    推送到MQ-根据roomid来更新合同、账单、预定、租客信息。 其中合同、账单、预定有自己的实体类格式
//    public void updateRoomElCon(RoomelUpdateReqVO roomelUpdateReqVO) {
//        streamBridge.send("RoomEsConsumerUpdate-out-0", roomelUpdateReqVO);
//    }

    //推送到MQ-房源-批量更新
    public void updateBatchRoomEl(List<RoomelUpdateReqVO> list) {
        Boolean result = iRoomelService.updateCoverBatch(list);
        log.info("消费-房源-批量更新，消费是否成功："+result);
        //streamBridge.send("RoomEsConsumerUpdateBatch-out-0", list);
    }

    //消费-房源-批量新增
    public void ListAddRoomEl(List<RoomelCreateReqVO> list) {
        log.info("消费-房源-批量新增");
        Boolean result = iRoomelService.listadd(list);
        log.info("消费-房源-批量新增,消费是否成功："+result);
        //streamBridge.send("RoomEsAConsumerListAdd-out-0", list);
    }

    //消费-房源-删除
    public void DeleteRoomEl(Long id) {
        Boolean result = iRoomelService.deleteByesid(id.toString());
        //streamBridge.send("RoomEsAConsumerDeleteById-out-0", id);
    }

}
